﻿using SqlSugar;

namespace WeDonekRpc.SqlSugar.Virtual
{
    internal class VirtualTable : IVirtualTable
    {
        private readonly SqlSugarProvider _Provider;
        private readonly DynamicProperyBuilder _builder;
        public VirtualTable ( SqlSugarProvider provider, string name, string show )
        {
            this._Provider = provider;
            this._builder = provider.DynamicBuilder().CreateClass(name, new SugarTable(name, show));
        }

        public void CreateProperty ( string propertyName, Type properyType, SugarColumn column = null, bool isSplitField = false, Navigate navigate = null )
        {
            _ = this._builder.CreateProperty(propertyName, properyType, column, isSplitField, navigate);
        }

        public Type Save ()
        {
            Type type = this._builder.BuilderType();
            this._Provider.CodeFirst.InitTables(type);
            return type;
        }
    }
}
